<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = '/home';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }

    /**
     * 获取最近十天的日期的数组
     * @return array
     */
    public function get_time()
    {
        //先获取当前的时间
        $now_time = strtotime(date('Y-m-d', time()));
        //需要获取的天数 如最近7天 10天
        $max_day = 10;
        //把一天转化成时间戳
        $one_day = 24 * 60 * 60;
        //循环得出当天时间和前一天时间之间的区间
        $time_arr = [];
        for ($i = 0; $i < $max_day; $i++) {
            //每天的开始时间
            $time_arr[$i]['min'] = date('Y-m-d H:i:s', ($now_time - $one_day * ($i + 1)));
            //每天的结束
            $time_arr[$i]['max'] = date('Y-m-d H:i:s', ($now_time - $one_day * $i));
        }
        $time_arr = array_reverse($time_arr);
        return $time_arr;
    }
}
